var pathName=window.document.location.pathname; 
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1); 

(function () {
  $.MsgBox = {
    Alert: function (title, msg, buttonOk) {
    	GenerateHtml("alert", title, msg, "", buttonOk, "");
    	btnOk(); //alert只是弹出消息，因此没必要用到回调函数callback
    	btnNo();
    	btnNo1();
    },
    Confirm: function (title, msg, buttonOk, buttonNo, callback) {
    	GenerateHtml("confirm", title, msg, "", buttonOk, buttonNo);
    	btnOk(callback);
    	btnNo();
    	btnNo1();
    },
    ConfirmOth: function (title, msg, buttonOk, buttonNo, callback,cancelback) {
        GenerateHtml("confirm", title, msg, "", buttonOk, buttonNo);
        btnOk(callback);
        btnNoOth(cancelback);
        btnNo1();
    },
    Prompt: function (title, msg, buttonFun, buttonOk, buttonNo, callbackFun, callback) {
        GenerateHtml("prompt", title, msg, buttonFun, buttonOk, buttonNo);
        btnFun(callbackFun)
        btnOk(callback);
        btnNo();
        btnNo1();
    }
  }
 
  //生成Html
  var GenerateHtml = function (type, title, msg, buttonFun, buttonOk, buttonNo) {
 
	  	var _html = "";
	  
	    _html += '<div id="mb_box"></div><div id="mb_con"><span id="mb_tit">' + title + '</span>';
	    _html += '<a id="mb_ico"></a><div id="bomb_line"></div><div id="bomb_icon"></div><div id="mb_msg">' + msg + '</div><div id="mb_btnbox">';
	 
	    if (type == "alert") {
	      _html += '<input id="mb_btn_ok" class="mb_btn mb_btn_alert_ok" type="button" value="' + buttonOk + '" />';
	    }
	    if (type == "confirm") {
	      _html += '<input id="mb_btn_ok" class="mb_btn mb_btn_confirm_ok" type="button" value="' + buttonOk + '" />';
	      _html += '<input id="mb_btn_no" class="mb_btn mb_btn_confirm_no" type="button" value="' + buttonNo + '" />';
	    }
	    if (type == "prompt") {
	        _html += '<input id="mb_btn_fun" class="mb_btn mb_btn_prompt_fun" type="button" value="' + buttonFun + '" />';
	        _html += '<input id="mb_btn_ok" class="mb_btn mb_btn_prompt_ok" type="button" value="' + buttonOk + '" />';
	        _html += '<input id="mb_btn_no" class="mb_btn mb_btn_prompt_no" type="button" value="' + buttonNo + '" />';
	      }
	    _html += '</div></div>';
	 
	    //必须先将_html添加到body，再设置Css样式
	    $("body").append(_html); GenerateCss();
  }
 
  //生成Css
  var GenerateCss = function () {
 
    $("#mb_box").css({ 
    	width: '100%', 
    	height: '100%', 
    	zIndex: '9999', 
    	position: 'fixed',
    	top: '0', 
    	left: '0',
    	backgroundColor: '#000',
    	opacity: '0.5'
    });
 
    $("#mb_con").css({ 
    	'z-index': '99999',
	    'position': 'absolute',
	    'background': 'url('+projectName+'/common/images/nms/common/bomb_bg.png)',
	    'width': '490px',
	    'height': '290px',
    	'margin-top': '-100px'
    });
    
    $("#mb_tit").css({ 
    	'font-size': '18px',
	    'color': '#fff',
	    'position': 'relative',
	    'top': '15px',
	    'left': '15px',
	    'height': '40px',
	    'line-height': '40px',
	    'background-color': '#1D2835',
	    'display': 'block',
	    'width': '460px',
	    'padding': '0 8px'
    });
 
    $("#mb_msg").css({ 
    	'font-size': '18px',
	    'color': '#000',
	    'position': 'relative',
	    'width': '460px',
	    'text-align': 'center',
    	'display': 'table-cell',
    	'vertical-align': 'middle',
    	'left': '15px',
    	'top': '15px',
    	'height': '192px'
    });
    
    $("#bomb_icon").css({ 
    	'background': 'url('+projectName+'/common/images/nms/bomb_icon.png)',
	    'width': '92px',
	    'height': '73px',
	    'background-size': '100% 100%',
	    'display': 'inline-block',
	    'position': 'absolute',
	    'margin-top': '97px',
	    'margin-left': '76px'
    });
 
    $("#mb_ico").css({ 
		'background-image': 'url('+projectName+'/common/images/nms/common/close_normal.png)',
		'width': '17px',
	    'height': '40px',
	    'position': 'absolute',
	    'right': '12px',
	    'top': '16px',
	    'background-repeat': 'no-repeat',
	    'background-position': 'center',
    	'margin-right': '12px'
    });
    
    $("#bomb_line").css({ 
    	'position': 'absolute',
	    'top': '37px',
	    'background': 'url("'+projectName+'/common/images/nms/listdelete_titleslip.png")',
	    'background-repeat': 'no-repeat',
	    'width': '100%',
	    'height': '1px',
	    'background-size': '100% 100%'
    }); 
    $("#mb_btnbox").css({ 
    	'position': 'absolute',
    	'bottom': '15px',
    	'width': '460px',
    	'text-align': 'center',
    	'left': '15px',
    	'background-color': '#D6DAE0'
	});
    $("#mb_btn_ok,#mb_btn_no").css({ 
    	'width': '110px',
	    'height': '30px',
	    'color': '#000',
	    'background': 'url("'+projectName+'/common/images/nms/usermanage/save_normal.png")',
	    'font-size': '14px',
	    'margin': '9px 20px'
	});
 
    $("#mb_btn_ok").hover(function () {
    	$(this).css({ 
    		'background': 'url("'+projectName+'/common/images/nms/usermanage/save_hover.png")'
    	});
    },function () {
    	$(this).css({ 
    		'background': 'url("'+projectName+'/common/images/nms/usermanage/save_normal.png")'
    	});
    });
    
    $("#mb_btn_no").css({
    	'margin-right': '1px'
    });
    
    $("#mb_btn_no").hover(function () {
    	$(this).css({ 
    		'background': 'url("'+projectName+'/common/images/nms/usermanage/save_hover.png")'
    	});
    },function () {
    	$(this).css({ 
    		'background': 'url("'+projectName+'/common/images/nms/usermanage/save_normal.png")'
    	});
    });
    //右上角关闭按钮hover样式
    $("#mb_ico").hover(function () {
    	$(this).css({ 
    		'background': 'url('+projectName+'/common/images/nms/common/close_hover.png)',
    		'background-repeat': 'no-repeat',
    	    'background-position': 'center'
    	});
    },function () {
    	$(this).css({ 
    		'background': 'url('+projectName+'/common/images/nms/common/close_normal.png)',
    		'background-repeat': 'no-repeat',
    	    'background-position': 'center'
    	});
    });
    var _widht = document.body.clientWidth; //屏幕宽
    var _height = document.body.clientHeight; //屏幕高
 
    var boxWidth = $("#mb_con").width();
    var boxHeight = $("#mb_con").height();
    //让提示框居中
    $("#mb_con").css({ top: (_height - boxHeight + 120) / 2  + "px", left: (_widht - boxWidth) / 2 + "px" });
  }
 
 
  //确定按钮事件
  var btnOk = function (callback) {
    $("#mb_btn_ok").click(function () {
    	$("#mb_box,#mb_con").remove();
    	$("#mb_btn_ok").css({
    		'background': 'url("'+projectName+'/common/images/nms/bomb_btn_down.png")'
    	});
    	if (typeof (callback) == 'function') {
    		callback();
    	}
    });
  }
  //取消回调按钮事件
  var btnNoOth = function (callback) {
	  $("#mb_btn_no").click(function () {
		  $("#mb_box,#mb_con").remove();
		  if (typeof (callback) == 'function') {
			  callback();
		  }
	  });
  }
  //取消按钮事件
  var btnNo = function () {
    $("#mb_btn_no").click(function () {
    	$("#mb_box,#mb_con").remove();
    	$("#mb_btn_no").css({
      	  'background': 'url("'+projectName+'/common/images/nms/bomb_btn_down.png")'
        });
    });
  }
  
  var btnNo1 = function () {
    $("#mb_ico").click(function () {
    	$("#mb_box,#mb_con").remove();
    	$("#mb_ico").css({
    		'background': 'url('+projectName+'/common/images/nms/common/close_active.png)',
    		'background-repeat': 'no-repeat',
    	    'background-position': 'center'
        });
    });
  }
})();